package com.service.setting.impl;

import com.comm.R;
import com.comm.vo.ProjectTableVo;
import com.entity.ProjectTable;
import com.github.pagehelper.PageHelper;
import com.mapper.setting.SystemProjecttableMapper;
import com.service.setting.SysPrescriptionService;
import com.service.setting.SystemProjecttableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SystemProjecttableServiceimpl implements SystemProjecttableService {
//查找所有的项目类型！！！

    @Autowired
    private SystemProjecttableMapper  systemProjecttableMapper;

    private int a = 1;
    private int okcode = 200;
    private int nocode = 500;

    @Override
    public R fundProjectTable(Integer currentPage, Integer pageSize) {
        R r = new R();
        try {
            com.github.pagehelper.Page<ProjectTable> page = PageHelper.startPage(currentPage,pageSize);
            List<ProjectTable> projectTables = systemProjecttableMapper.fundProjectTable();
            int fundcount = systemProjecttableMapper.fundcount();
            r.setCode(200);
            r.setMsg("查到了");
            r.setCount(fundcount);
            r.setData(projectTables);
            return  r;
        }catch (Exception e){
            e.printStackTrace();
            r.setMsg("查询错误");
            r.setCode(500);
            return  r;
      }

    }

    @Override
    public R fundProjectTable() {
                    R r = new R();
            try {
                List<ProjectTable> projectTables = systemProjecttableMapper.fundProjectTable();
                r.setCode(200);
                r.setMsg("查到了");
                r.setData(projectTables);
                return  r;
            }catch (Exception e){
                e.printStackTrace();
                r.setMsg("查询错误");
                r.setCode(nocode);
                return  r;
            }
    }

    @Override
    public R addProject(String projectName) {
        R r = new R();
        try {
            int i = systemProjecttableMapper.addProject(projectName);
            r.setCode(okcode);
            r.setMsg("添加成功！！！"+a++ +"次");
            return r;

        }catch (Exception e) {
            e.printStackTrace();
            r.setMsg("发生了一个莫名其妙的错误" + a + "次");
            r.setCode(nocode);
            return r;
        }
    }

    @Override
    public R editProject(ProjectTableVo projectTableVo) {
        R r = new R();
        try {
            int i = systemProjecttableMapper.editProject(projectTableVo);
            r.setCode(okcode);
            r.setMsg("编辑成功！！！"+a++ +"次");
            return r;


        }catch (Exception e){
            e.printStackTrace();
            r.setMsg("发生了一个莫名其妙的错误"+a +"次");
            r.setCode(nocode);
            return  r;

        }



    }

    @Override
    public R delProject(Integer id) {
        R r = new R();
        try {
            int i = systemProjecttableMapper.delProject(id);
            r.setCode(okcode);
            r.setMsg("删除成功！！！"+a++ +"次");
            return r;

        }catch (Exception e){
            e.printStackTrace();
            r.setMsg("发生了一个莫名其妙的错误"+a);
            r.setCode(nocode);
            return  r;

        }
    }

}
